#include "FdInfos.hpp"

int  FdInfos::FdIsset(int	fd,
		      Fd_Set	&fdSet)
{
  return FD_ISSET(fd, &fdSet);
}

void   FdInfos::FdZero(Fd_Set   &fdSet)
{
  FD_ZERO(&fdSet);
}

void   FdInfos::FdSet(int       fd,
		     Fd_Set    &fdSet)
{
  FD_SET(fd, &fdSet);
}

int	FdInfos::InitFdClient(int	fd)
{
  int		max;
  
  FdZero(Readf);
  FdZero(Writef);
  max = fd;
  FdSet(fd, Readf);
  FdSet(fd, Writef);
  return (max);
}

int	FdInfos::InitFdServer(int	fd,
			      std::list<Connected *> Co)
{
  int		max;
  std::list<Connected *>::iterator it;
  Connected *co;

  FdZero(Readf);
  FdZero(Writef);
  max = fd;
  FdSet(fd, Readf);
  it = Co.begin();
  while (it != Co.end())
    {
      co = (*it);
      if (max < co->GetFd())
	max = co->GetFd();
      FdSet(co->GetFd(), Readf);
      FdSet(co->GetFd(), Writef);
      it++;
    }
  return (max);
}

Fd_Set        &FdInfos::GetReadf(void)
{
  return Readf;
}

Fd_Set        &FdInfos::GetWritef(void)
{
  return Writef;
}
